package com.AI.AIDemo.Demos;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lenovo
 * {@code @Author:大力王}
 * {@code @Date:2025/10/13-13-9:50}
 * 开始了  */

@Slf4j
@Data
@AllArgsConstructor
public class DecisionTree {
    private int inputSize;
    private int outputSize;

    public int predict(double[] input) {
        // 创建一个数组来保存每个节点的概率
        double[] nodeProbabilities = new double[inputSize];

        // 计算每个节点的概率
        for (int i = 0; i < inputSize; i++) {
            nodeProbabilities[i] = Math.exp(input[i]);
        }

        // 计算概率和
        double sum = 0;
        for (double probability : nodeProbabilities) {
            sum += probability;
        }

        // 计算每个节点的概率
        for (int i = 0; i < inputSize; i++) {
            nodeProbabilities[i] /= sum;
        }
        return (int) (Math.random() * outputSize);
    }
}
